#!/usr/bin/env python

"""
networkTopo.py: Create a simple SDN network topology using Mininet.
"""

import mininet.topo
import mininet.net
import mininet.node
import mininet.cli
import mininet.log
import mininet.term

class SimpleTopo(mininet.topo.Topo):
    """
    SimpleTopo: A simple topology with one switch and three hosts.
    """

    def build(self):
        """
        Build the topology.
        """
        # Add a switch
        switch = self.addSwitch('s1')

        # Add hosts
        client = self.addHost('client', ip='10.0.1.5/24', mac='00:00:00:00:00:03')
        server1 = self.addHost('server1', ip='10.0.1.2/24', mac='00:00:00:00:00:01')
        server2 = self.addHost('server2', ip='10.0.1.3/24', mac='00:00:00:00:00:02')

        # Add links
        self.addLink(client, switch)
        self.addLink(server1, switch)
        self.addLink(server2, switch)

def run():
    """
    Create and run the network.
    """
    topo = SimpleTopo()
    net = mininet.net.Mininet(topo=topo, controller=mininet.node.RemoteController)

    # Add a controller
    c1 = net.addController('c1', controller=mininet.node.RemoteController)

    net.start()

    # Start xterms for each node
    net.terms += mininet.term.makeTerm(c1)
    net.terms += mininet.term.makeTerm(net.get('s1'))
    net.terms += mininet.term.makeTerm(net.get('client'))
    net.terms += mininet.term.makeTerm(net.get('server1'))
    net.terms += mininet.term.makeTerm(net.get('server2'))

    mininet.cli.CLI(net)
    net.stop()

if __name__ == '__main__':
    mininet.log.setLogLevel('info')
    run()
